package com.by.controller;

import com.by.bean.ProductCategory;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.service.ProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Ye QS
 * @version 0.1
 * @className ProductCategoryController
 * @description
 * @date 2024/9/23 15:36
 * @since jdk11
 */
@RestController
@RequestMapping("/v1")
@Api(tags = "产品分类")
public class ProductCategoryController extends BaseController {
    @Autowired
    ProductCategoryService productCategoryService;
    @ApiOperation("保存类别")
    @PostMapping("/product/category")
    public ResultBean save(@Validated @RequestBody ProductCategory productCategory, BindingResult result){
        int rs=productCategoryService.save(productCategory);
        return saveResult(rs);
    }
    @ApiOperation("修改类别")
    @PutMapping("/product/category")
    public ResultBean update(@Validated @RequestBody ProductCategory productCategory, BindingResult result){
        int rs=productCategoryService.update(productCategory);
        return updateResult(rs);
    }



    @ApiOperation("删除")
    @DeleteMapping("/product/category")
    public ResultBean delete(@RequestParam(required = true) int id){
        int rs=productCategoryService.delete(id);
        return deleteResult(rs);
    }


    @ApiOperation("分类列表")
    @GetMapping("/product/category")
    public ResultBean query(){
        List list=productCategoryService.queryAll();
        return success("分类列表",list);
    }
}
